var page = 1;
Page({
  
  data: {
    noInfo: false,
    loading: false,
  },
  
  call(id) {
    this.data.orders.forEach(e => {
      if (e.id_kd_order == id.currentTarget.id) {
        wx.modal("联系客户", "客户姓名："+e.kd_name,
        "取消", "拨打电话", null, null, res => {
          wx.makePhoneCall({
            phoneNumber: e.kd_phone,
          })
        }
        )
        return 1;
      }
    });
  },

  onLoad() {
    page = 1;
    this.setData({ loading: true, noInfo: false });
    wx.post('getStaffOrder', {
      unionid: wx.appData.user.unionid
    }, res => {
      this.setData({ loading: false });
      wx.stopPullDownRefresh();
      if (!res.ok) {
        this.setData({ noInfo: true });
        return 0;
      }
      res.data.forEach(e => {
        e.id = (Array(6).join(0) + e.id_kd_order).slice(-6);
        e.price = parseFloat(e.price).toFixed(2);
      })
      this.setData({ orders: res.data });
      ++page;
    })
  },

  onPullDownRefresh() {
    this.onLoad();
  },

  onReachBottom: function () {
    if (this.data.noInfo) return;
    this.setData({ loading: true });
    wx.post('getStaffOrder', {
      unionid: wx.appData.user.unionid,
      page: page,
    }, res => {
      this.setData({ loading: false });
      if (!res.ok) {
        this.setData({ noInfo: true });
        return 0;
      }
      res.data.forEach(e => {
        e.id_kd_order = (Array(6).join(0) + e.id_kd_order).slice(-6);
        e.price = parseFloat(e.price).toFixed(2);
      })
      this.setData({ orders: this.data.orders.concat(res.data)})
      ++page;
    })
  },

  ViewImage(e) {
    wx.previewImage({
      urls: [e.currentTarget.id],
      current: e.currentTarget.id
    });
  },

  onShareAppMessage: function () {
    
  }
})